// 6. 计算试卷成绩
(function () {
  let score = 0

  document.querySelector('.top-nav a').addEventListener('click', function () {
    score = 0
    // 使用reduce方法计算本次成绩
    score = questionList.reduce((sum, item, i) => {
      const answer = localStorage.getItem(`answered_${i}`)
      // console.log(index, answer)
      if (answer === item.correctAnswer) sum += 2
      // console.log(item.correctAnswer)
      return sum
    }, score)

    // 存储历史成绩
    user[index].historicalScore.push(score)
    localStorage.setItem('exam-data', JSON.stringify(user))

    // 临时成绩存储
    localStorage.setItem('score', score)

    // 跳转页面
    location.href = './look.html'
  })
})()